import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/index.vue'),
    children: [{ //订单管理
      path: '/background',
      name: 'background',
      component: () => import('../views/home/background.vue'),
    }, { //发票管理
      path: '/album',
      name: 'album',
      component: () => import('../views/home/album.vue'),
    }, { //售后服务
      path: '/shoplist',
      name: 'shoplist',
      component: () => import('../views/home/shoplist.vue'),
    }]
  },
  { //订单管理
    path: "/order",
    name: "order",
    component: () =>
      import("../views/order/index.vue"),
    children: [{ //订单管理
      path: "/orders",
      name: "orders",
      component: () =>
        import("../views/order/orders.vue"),
    }, { //发票管理
      path: "/invo",
      name: "invo",
      component: () =>
        import("../views/order/invo.vue"),
    }, { //售后服务
      path: "/aftersale",
      name: "aftersale",
      component: () =>
        import("../views/order/aftersale.vue"),
    }]
  }, { //订单
    path: "/shop",
    name: 'shop',
    component: () =>
      import("../views/shop/index.vue"),
      children:[{
        path: "/orderpage",
        name: 'orderpage',
        component: () =>
          import("../views/shop/orderpage.vue"),
      }]
  },
  { //会员
    path: "/vip",
    name: 'vip',
    component: () =>
      import("../views/vip/index.vue"),
  },
  { //会员
    path: "/setup",
    name: 'setup',
    component: () =>
      import("../views/setup/index.vue"),
  }


]

const router = new VueRouter({
  routes
})

export default router

// 全局守卫
router.beforeEach((to, form, next) => {
  if (localStorage.getItem("token")) {
    next();
  } else {
    if (to.path == '/login') {
      next();
    } else {
      next('/login')
    }
  }
})